<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Time and Memory
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial034.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial036.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc74">4.12</A>&nbsp;&nbsp;Time and Memory</H2><UL>
<LI><A HREF="tutorial035.html#toc41">Timing</A>
</UL>

<A NAME="toc41"></A>
<H3 CLASS="subsection"><A NAME="htoc75">4.12.1</A>&nbsp;&nbsp;Timing</H3>
Timings are available via the built-in predicates
<A HREF="a"><B>cputime/1</B></A><A NAME="@default118"></A>nd
<A HREF="."><B>statistics/2</B></A><A NAME="@default119"></A>
To obtain the CPU time consumption of a (succeeding) goal, use the scheme
<BLOCKQUOTE CLASS="quote"> <PRE CLASS="verbatim">
cputime(StartTime),
my_goal,
TimeUsed is cputime-StartTime,
printf("Goal took %.2f seconds%n", [TimeUsed]).
</PRE></BLOCKQUOTE>
The
<A HREF="../bips/kernel/env/statistics-2.html"><B>statistics/2</B></A><A NAME="@default120"></A> and <A HREF="../bips/kernel/env/statistics-0.html"><B>statistics/0</B></A><A NAME="@default121"></A>
commands can also be used to obtain memory usage information.
The memory areas used by ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> are:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<B>Shared and private heap</B><DD CLASS="dd-description"> for compiled code, non-logical store (
 bags and shelves, findall)
 dictionary of functors, various tables and buffers.
<DT CLASS="dt-description"><B>Global stack</B><DD CLASS="dd-description"> for most ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> data like lists, structures, suspensions.
 This is likely to be the largest consumer of memory.
<DT CLASS="dt-description"><B>Local stack</B><DD CLASS="dd-description"> for predicate call nesting and local variables.
<DT CLASS="dt-description"><B>Control and trail stack</B><DD CLASS="dd-description"> for data needed on backtracking.
</DL>
Automatic garbage collection is done on the global and trail stack,
and on the dictionary. Garbage collection parameters can be set using
<A HREF="../bips/kernel/env/set_flag-2.html"><B>set_flag/2</B></A><A NAME="@default122"></A>
and an explicit collection can be requested using
<A HREF="../bips/kernel/env/garbage_collect-0.html"><B>garbage_collect/0</B></A><A NAME="@default123"></A>.<BR>
<BR>
<HR>
<A HREF="tutorial034.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial023.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial036.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
